package com.miniot.base.controller;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.miniot.base.entity.BoundDetail;
import com.miniot.base.service.BoundDetailService;
import com.miniot.business.base.BaseController;
import com.miniot.business.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 无
 *
 * @author fpf
 * @date 2023-10-16 17:36:39
 */
@RestController
@AllArgsConstructor
@RequestMapping("/bounddetail" )
@Api(value = "出入库详情表(后台)", tags = "出入库详情表-后台接口")
public class BoundDetailController extends BaseController {

    private final BoundDetailService boundDetailService;

    /**
    * 分页查询
    * @param currentPage 当前页数
    * @param pageSize 每页数据量
    * @param boundDetail 查询条件
    * @return 查询结果
    */
    @GetMapping("/listPage")
    @ApiOperation(value = "分页查询", notes = "传入分页信息与查询条件")
    public R<Page<BoundDetail>> listBoundDetailPage(
            @ApiParam(value = "当前页数", required = true, defaultValue = "1") @RequestParam Long currentPage,
            @ApiParam(value = "每页数据量", required = true, defaultValue = "10") @RequestParam Long pageSize,
            @ApiParam(value = "查询条件") String warehouseName) {
        Page<BoundDetail> page = new Page<BoundDetail>(currentPage, pageSize);
        LambdaQueryWrapper<BoundDetail> wrapper = new LambdaQueryWrapper();

        return R.success(boundDetailService.page(page,null),"分页信息查询成功");
    }


    /**
    * 通过id查询出入库详情表
    * @param id id
    * @return Result
    */
    @GetMapping("/getById")
    @ApiOperation(value = "通过id查询库存变更详情", notes = "传入id")
    public R<BoundDetail> getBoundDetailById(@ApiParam(value = "id", required = true) @RequestParam("id") Long id) {
        return R.success(boundDetailService.getById(id));
    }

    /**
    * 新增出入库详情表
    * @param boundDetail
    * @return Result
    */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "传入BoundDetail数据")
    public R<Boolean> save(@RequestBody BoundDetail boundDetail) {
        Assert.isTrue(boundDetailService.save(boundDetail), "操作失败");
        return R.success(true,"新增成功");
    }

    /**
    * 修改出入库详情表
    * @param boundDetail 无
    * @return Result
    */
    @PostMapping("/updateById")
    @ApiOperation(value = "修改", notes = "传入BoundDetail数据")
    public R<Boolean> updateById(@RequestBody BoundDetail boundDetail) {
        Assert.isTrue(boundDetailService.updateById(boundDetail), "修改失败");
        return R.success(true,"修改成功");
    }

    /**
    * 通过id删除出入库详情表
    * @param id id
    * @return Result
    */
    @GetMapping("/deleteById")
    @ApiOperation(value = "通过id删除", notes = "传入id")
    public R<Boolean> deleteById(
            @ApiParam(value = "id", required = true) @RequestParam("id") Long id) {
        Assert.isTrue(boundDetailService.removeById(id), "操作失败");
        return R.success(true,"删除成功");
    }
}